package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectDemo7 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class cls = Class.forName("reflect.Person");
        Object o = cls.newInstance();
        //say(String)
        //第二个参数开始为参数列表
        Method method = cls.getDeclaredMethod("say",String.class,int.class);
        //调用方法时从第二个参数开始为方法的实际参数
        method.invoke(o,"嘿嘿",5);
    }
}
